<?php

define('XMPP_ACCOUNT_PARENT', 'object');
define('XMPP_ACCOUNT_SUBTYPE', 'xmpp_account');
define('XMPP_ACCOUNT_CLASS', 'XMPPAccount');

define('XMPP_ACCOUNT_LOGIN', 'login');
define('XMPP_ACCOUNT_DOMAIN', 'domain');

register_entity_type(XMPP_ACCOUNT_PARENT, XMPP_ACCOUNT_SUBTYPE);
// This operation only affects the db on the first call for this subtype
// If you change the class name, you'll have to hand-edit the db
add_subtype(XMPP_ACCOUNT_PARENT, XMPP_ACCOUNT_SUBTYPE, XMPP_ACCOUNT_CLASS);

class XMPPAccount extends ElggObject {

    protected function initialise_attributes() {
        parent::initialise_attributes ();
        $this->attributes ['subtype'] = XMPP_ACCOUNT_SUBTYPE;
        $this->access_id = ACCESS_PUBLIC;
    }

    public function __construct($guid = null) {
        parent::__construct($guid);
    }

    public function setOwner($guid) {
        $this->owner_guid = $guid;
        $this->save();
    }

    // more customizations here
    public function saveAccount($login, $domain) {
        $this->save();
        $this->setMetaData(XMPP_ACCOUNT_LOGIN, $login, 'text');
        $this->setMetaData(XMPP_ACCOUNT_DOMAIN, $domain, 'text');
        return $this->save();
    }

    public function toArray() {
        return array(
            'guid' => $this->getGUID(),
            'login' => $this->login,
            'domain' => $this->domain
        );
    }

}

?>